<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="https://cdn.tailwindcss.com"></script>
    <script>
      tailwind.config = {
        darkMode: 'class',
      }
    </script>
    <style>
      .toggle-checkbox:checked {
        right: 0;
        border-color: #68d391;
      }
      .toggle-checkbox:checked + .toggle-label {
        background-color: #68d391;
      }
    </style>
    <title>Dark Mode</title>
  </head>
  <body>
    <!-- By default, you can have your project use whatever mode your OS is using. You can use "dark:{class}". You can also set your config to use a class instead of using your OS mode -->
    <div class="container mx-auto m-10 dark:bg-slate-900 rounded-xl px-6 py-8 shadow-xl transition-colors duration-700">
      <h1 class="text-xl dark:text-slate-200">Lorem ipsum dolor sit amet consectetur.</h1>
      <p class="dark:text-slate-400 text-slate-500">
        Lorem ipsum dolor sit amet consectetur adipisicing elit. Ea ratione eveniet repellendus? Quis, exercitationem
        modi.
      </p>
    </div>
    <div class="relative inline-block w-10 mr-2 align-middle select-none">
      <input
        type="checkbox"
        name="toggle"
        id="toggle"
        class="toggle-checkbox absolute block w-6 h-6 rounded-full bg-white border-4 appearance-none cursor-pointer"
      />
      <label
        for="toggle"
        class="toggle-label block overflow-hidden h-6 rounded-full bg-gray-300 cursor-pointer"
      ></label>
    </div>
    <script>
      const input = document.querySelector('#toggle')
      const body = document.body
      input.addEventListener('change', function () {
        if (this.checked) {
          body.classList.add('dark')
        } else {
          body.classList.remove('dark')
        }
      })
    </script>
  </body>
</html>

<!-- Credit for toggle button style
https://tailwindcomponents.com/component/toggle-switch
 -->
